package org.ns.example.service;

import org.ns.example.pojo.Resume;
import org.ns.example.dao.ResumeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ResumeService {
    @Autowired(required = false)
    ResumeDao resumeDao;

    public Map<String, Object> list() {
        Map<String, Object> respMap = new HashMap<>();
        List<Resume> resumes = resumeDao.findAll();
        respMap.put("static", 0);
        respMap.put("content", resumes);
        return respMap;
    }

    public Map<String, Object> add(String name, String address, String phone) {
        Map<String, Object> respMap = new HashMap<>();
        respMap.put("static", 0);
        resumeDao.save(new Resume(name, address, phone));
        return respMap;
    }

    public Map<String, Object> del(Long id) {
        Map<String, Object> respMap = new HashMap<>();
        respMap.put("static", 0);
        if (id != null) {
            resumeDao.deleteById(id);
        }
        return respMap;
    }
}
